Hi All, Can anyone please help me out as the function which I have written is not counting the no of weak word count in attribute "Object Text".
The function is:
KBSri - Wed Feb 19 00:00:35 EST 2014 |
Re: Count of weak words in Object text attribute Oh well ... 1st of all, that MEGA function could use some partitioning into smaller better verifyable parts. 2ndly you use a lot of global variables inside the function like "flag_attribute_object_type" (or you might have autodeclare enabled?). Do neither! This makes your code hard to understand. and last but not least you should include a good error description, otherwise nobody will know what to look for. Instead of telling us only what the code is not doing, you should tell us what unexpected result you are getting, and why you think this is wrong and what should happen instead. And for large code bits you should either use the <> code insert button or attach the code as a file. A working example that reproduces your result maximizes the chances for a quick answer. Regards, Mathias |
Re: Count of weak words in Object text attribute Mathias Mamsch - Wed Feb 19 09:34:38 EST 2014 Oh well ... 1st of all, that MEGA function could use some partitioning into smaller better verifyable parts. 2ndly you use a lot of global variables inside the function like "flag_attribute_object_type" (or you might have autodeclare enabled?). Do neither! This makes your code hard to understand. and last but not least you should include a good error description, otherwise nobody will know what to look for. Instead of telling us only what the code is not doing, you should tell us what unexpected result you are getting, and why you think this is wrong and what should happen instead. And for large code bits you should either use the <> code insert button or attach the code as a file. A working example that reproduces your result maximizes the chances for a quick answer. Regards, Mathias Hello mathias, I am a newbie. Thanks for the advice. But this was the code already existing I just have to enable the Weak word functionality. I should be able to count the number of weak words in the attribute "Object Text". The number of weak words are already listed in the array.
E.g: string weak_words[] = {"about","absolutely","absolute","according to","actually","additionally","a few", //- The problem is that it is not counting the weak words in the current modues in the folders. Any help would be appreciated. |
Re: Count of weak words in Object text attribute KBSri - Thu Feb 20 08:20:46 EST 2014 Hello mathias, I am a newbie. Thanks for the advice. But this was the code already existing I just have to enable the Weak word functionality. I should be able to count the number of weak words in the attribute "Object Text". The number of weak words are already listed in the array.
E.g: string weak_words[] = {"about","absolutely","absolute","according to","actually","additionally","a few", //- The problem is that it is not counting the weak words in the current modues in the folders. Any help would be appreciated. Let me rephrase my question: How do you know the code is not counting the weak words in the current module (i.e. what IS the code doing)? And how do you call your function? See it could have 100 reasons why you think the code is not working ... Maybe the code is wrong. Maybe you are just expecting the output to be different than it really is. Maybe you evaluate the output of the function wrong. Maybe you put in wrong parameters. So before we start searching, you need to tell us, what you put into the function and what you get out and what you expect to get out of the function. Regards, Mathias |
Re: Count of weak words in Object text attribute Mathias Mamsch - Thu Feb 20 08:50:17 EST 2014 Let me rephrase my question: How do you know the code is not counting the weak words in the current module (i.e. what IS the code doing)? And how do you call your function? See it could have 100 reasons why you think the code is not working ... Maybe the code is wrong. Maybe you are just expecting the output to be different than it really is. Maybe you evaluate the output of the function wrong. Maybe you put in wrong parameters. So before we start searching, you need to tell us, what you put into the function and what you get out and what you expect to get out of the function. Regards, Mathias Hello mathias, Can I post the code? |
Re: Count of weak words in Object text attribute KBSri - Thu Feb 20 11:52:51 EST 2014 Hello mathias, Can I post the code? Hello, Part of the trouble is that 99% of the posted code has nothing to do with actually checking for weak words. So, for others to help, it is better to focus on the specific issue. Otherwise, hire a consultant to fix your problem.
I noticed in the code the following line: weak_word = ".*([ ]"weak_word_text"[ .])" You may want to try and put spaces before and after weak_word_text so that the interpreter can better recognize that this is a variable. Hope this helps, Greg |
Re: Count of weak words in Object text attribute Follow MMs advise. In this case your main function could accept the "Module" handle, and you could write a separate function that checks a single "Object". I'd be tempted to write another function that checks a single "string Text" for weak words. Since that is your "main" function it will be pretty easy to "test" it by just calling it with a variety of strings. It may thus may look like this: bool CheckText(string Text) { does the Text have a weak word?} bool CheckObject(Object obj) { string Text = obj."Object Text"; return CheckText(Text)} bool CheckModule(Module mod) { for each obj; if the object qualies then CheckObject(obj); report findings} Notice the ease of changing the program to check the "Proposed Text" attribute; if needed in the future. Anyway ... To answer your question: Regular expressions routinely stop looking at the end of the input or the end of the line. Since you are often searching for Text that follows an EOL, your regular expression won't work. I don't recall what to do about that, other than don't use Reqular expressions in the first place; (although someone else will advise on how to fix it). You can put your Object Text into a Buffer, and use the "contains(buf, string)" function to find whole words, and don't need the Regular Expressions at all. Also... That "Progress" for for the birds. This function can scan an entire module very fast and there is no reason to be updating the "Progress" for every object. "Refresh" doesn't help you. There is no reason this function must work on a displayed module anyway. If you add "entire" to your object loop, you are good to go (since you then check for isDeleted objects, and do some other does-object-qualify checking). Printing "sucess" for each object should drastically slow you down for large modules. Instead put these lines into a buffer, and print the buffer at the end. You should FIRST plow through your weak_words list, creating corresponding Regular Expressions for them only a single time. Store the in a Skip; then apply them from the Skip. As it is you are creating 1000s of useless "Allocation Units" (each "regexp2") without freeing them up. Your "ancestor_info" concatenation inside a loop is a small disaster. Deep modules can easily cause you to run out of memory doing that. Again, accumulate results in a Buffer. Seems to me you should count/accumulate all the "weak_words" for a particular object, then report that object only once if it has any. If the module is visible, then perhaps cleverly either "accept" or "reject" the object depending on your findings, and turn filtering on at the end. -Louie Any kind of "s = s concatenated with something else" inside a loop is to be avoided.
You end up with 1000 "A's" in the result, but if I did my math correctly you wasted a whopping 500,000 bytes in intermediate strings. That is 1/4 your legal memory space for DOORS. This is far better and should be routine:
There you end up with the same result, I have no doubt significantly faster, and have "wasted" only 1001 bytes. Trust me, start using Buffers now. |